package com.server.http.controller;

import com.server.dao.*;
import com.server.pojo.*;
import com.server.http.service.AlarmService;
import com.server.http.service.MobileAppService;
import com.server.libs.ret.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping(value = "/notice")
@Slf4j
@Transactional
public class NoticeController {
    @Autowired
    AlarmDao alarmDao;
    @Autowired
    UnitDao unitDao;

    @Autowired
    MobileAppService mobileAppService;

    @Autowired
    MobileAppDao mobileAppDao;

    @Autowired
    AlarmService alarmService;

    @Autowired
    AlarmMessageDao alarmMessageDao;

    @Autowired
    MobileAppNoticeDao mobileAppNoticeDao;

    @RequestMapping(value = "/all", method = {RequestMethod.GET, RequestMethod.POST})
    public R<List<Notice>> all(@RequestHeader String authorization, @RequestBody Map<String,Object> map) {
        int page = map.containsKey("page") ? (Integer) map.get("page") : 0;
        int size = map.containsKey("size") ? (Integer) map.get("size") : Integer.MAX_VALUE;
        MobileApp mobileApp = mobileAppService.checkLogin(authorization);
        Pageable pageable = PageRequest.of(page, size);
        List<Notice> all = mobileAppNoticeDao.getNotice(mobileApp, pageable).toList();

        return new R<List<Notice>>("ok").setData(all);
    }


}
